{extend name="AdminController/index" /}
{block name="main"}

<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<div class="content-page">
    <div class="content">
        <h1>{$title}</h1>
        <form name='searchform' action="{:url('search')}" method='get'>
            <input name='keyword' class="form-control" type='text' value='<?php echo input(' get.keyword');?>' ' />
            <input type='submit' name='search' class='button btn btn-success' vlalue='<?php echo lang(' search')?>' />
        </form>
    </div>
    {if !empty($list)}
    <div>
        <table class="table table-striped">
            <thead>
            <tr>
                <th>ID</th>
                <th>昵称</th>
                <th>头像</th>
                <th>手机</th>
                <th>邮箱</th>
                <th>创建时间</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="list" id="vo"}
            <tr>
                <td>{$vo.id}</td>
                <td>{$vo.name} </td>
                <td>
                    {if $vo.face==''}
                    <img src="/static/index/face/face.png" alt="" width="30">
                    {else/}
                    <img src="/uploads/{$vo.face}" alt="" width="30">
                    {/if}
                </td>
                <td>{$vo.phone} </td>
                <td>{$vo.email} </td>
                <td>{$vo.createtime} </td>
                {if condition="($vo.status == 0)"} <td>禁用</td>
                {elseif condition="$vo.status eq 1"/}<td>启用</td>
                {/if}
                <td>
                    <button class="btn btn-danger btn del-btn" data-id="{$vo.id}">删除</button>

                    <a href="{:url('edit', ['id'=>$vo['id']])}" class="btn btn-warning btn">编辑</a>

                </td>
            </tr>
            {/volist}


            </tbody>
        </table>
        {else /} {$res}
        {/if}
    </div>
    <script>
        $(function () {
            // 设置弹框参数
            toastr.options = {
                closeButton: true,// 是否显示关闭按钮
                progressBar: true,// 实现显示计时条
                timeOut: "3000",  // 自动关闭时间
                positionClass: "toast-bottom-right" // 提示位置
                // toast-top-full-width 顶端，宽度铺满整个屏幕
                // toast-top-right  顶端右边
            };
            // 触发删除用户
            $('.del-btn').click(function () {
                var ac_id = $(this).attr('data-id');
                console.log('删除操作,ID:', ac_id);
                if (confirm('你确定要删除吗?!')) {
                    var ccc = $(this).parent().parent();
                    var obj = $(this).parents('tr');
                    // console.log(obj);
                    delAjax(ac_id, obj);
                }
            });
            // AJAX删除
            function delAjax(id, obj) {
                console.log(obj);
                $.ajax({
                    type: 'post',
                    url: 'delete',
                    data: {
                        id: id
                    },
                    dataType: 'json',
                    success: function (data) {
                        console.log(data);
                        if (data.status) {
                            // 将该条目删除掉
                            obj.remove();
                        } else {
                        }
                    },
                    error: function () {
                        alert('AJAX操作失败');
                    }
                });
            }


            // 触发查询单个用户信息
            $('.empower-btn').click(function () {
                var ac_id = $(this).attr('data-id');
                // console.log('分配权限操作,ID:', ac_id);
                empower(ac_id); // 指定查看信息操作
            });

            // 执行AJAX查询
            function empower(id) {
                $.ajax({
                    type: 'post',
                    data: {
                        id: id
                    },
                    url: 'checkPower',
                    dataType: 'json',
                    success: function (resource) {
                        console.log(resource);
                    },
                    error: function () {
                        alert('AJAX操作失败');
                    }
                });
            }

        })
    </script>
</div>


{js href="/static/admin/js/toastr.min.js"}
{js href="/static/admin/js/jquery.min.js"}
{js href="/static/admin/js/bootstrap.min.js"}


{/block}

